/**************************************************************
  > File Name: 14.c
  > Author: LuoLiang
  > Mail: 1204553475@qq.com 
  > Created Time: 2022年01月28日 星期五 14时14分32秒
 **************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

char * longestCommonPrefix(char ** strs, int strsSize)
{
	int i, j;
	int k = 0;
	char *buff = malloc(sizeof(char) * strlen(strs[0]) + 1);

	if (strsSize == 0)
		return NULL;
	if (strsSize == 1)
		return strs[0];

	for (j = 0; j < strlen(strs[0]); j++, k++)
	{
		for (i = 1; i < strsSize; i++)
		{
			if (strs[0][j] != strs[i][j])
			{
				break;
			}
			else
			{
				buff[k] = strs[i][j];
			}
		}
	}
	buff[k] = '\0';
	return buff;
}

int main(int argc,char **argv)
{
	char *buff[] = {"floiuss","flow","flower"};	
	char *ret = NULL;

	ret = longestCommonPrefix(buff,sizeof(buff) / sizeof(*buff));
	puts(ret);
    exit(0);
}
